import {managers, modules, services} from "../../engines/gameEngine";
import {VIBRATE_TYPE} from "../../engines/services/miniGameContent/miniApp";

const {ccclass, property} = cc._decorator;

@ccclass
export default class gameSetting extends cc.Component {

    // LIFE-CYCLE CALLBACKS:
    @property({type: [cc.SpriteFrame], displayName: '音效开关精灵帧'})
    spfArySound: cc.SpriteFrame[] = [];
    @property({type: [cc.SpriteFrame], displayName: '振动开关精灵帧'})
    spfAryVibrate: cc.SpriteFrame[] = [];
    @property(cc.Sprite)
    spSound: cc.Sprite = null;
    @property(cc.Sprite)
    spVibrate: cc.Sprite = null;

    onLoad() {

    }

    start() {
        modules().uiControlModule.showHideDialogAnimation(this.node.getChildByName('center'), true);
    }

    onBtnClose() {
        managers().soundMgr.playSound('mainSound/anNiu').then();
        managers().soundMgr.playVibrate();
        modules().uiControlModule.showHideDialogAnimation(this.node.getChildByName('center'), false, () => {
            this.node.destroy();
        });
    }

    onBtnSwitchSet(event: any, custom: string) {
        switch (custom) {
            case 'sound': {
                managers().soundMgr.setSoundEnabled(!managers().soundMgr.isSoundEnabled());
                break;
            }
            case 'vibrate': {
                managers().soundMgr.setVibrateEnabled(!managers().soundMgr.isVibrateEnabled());
                break;
            }
        }
        managers().soundMgr.playSound('mainSound/anNiu').then();
        managers().soundMgr.playVibrate();
    }

    update(dt) {
        this.spSound.spriteFrame = this.spfArySound[Number(managers().soundMgr.isSoundEnabled())];
        this.spVibrate.spriteFrame = this.spfAryVibrate[Number(managers().soundMgr.isVibrateEnabled())];
    }
}
